package com.xmkj.carwash.mine.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.methods.TixianMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.rxbus.RxBus;
import com.common.rxbus.postevent.RxKeyEvent;
import com.common.utils.EmptyUtils;
import com.xmkj.carwash.R;

/**
 * Create by leo
 * 创建日期：2018/4/9
 * 描述：
 */

public class TiXianActivity extends BaseMvpActivity {
    EditText etMoney;
    EditText etName;
    EditText etAccount;
    TextView tv_tixian;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_tixian;
    }

    @Override
    protected void onViewCreated() {
        etMoney = findViewById(R.id.et_money);
        etName = findViewById(R.id.et_name);
        etAccount = findViewById(R.id.et_count);
        tv_tixian = findViewById(R.id.tv_tixian);
    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(tv_tixian);
    }

    @Override
    protected void onViewClicked(View view) {
        if (view.getId() == tv_tixian.getId()) {
            if (EmptyUtils.isEmpty(getEditTextStr(etAccount)) || EmptyUtils.isEmpty(getEditTextStr(etAccount)) || EmptyUtils.isEmpty(getEditTextStr(etAccount)) || Integer.valueOf(getEditTextStr(etMoney)) == 0) {
                showToastMsg("请输入完整信息");
                return;
            }
            gotoTixian();
        }
    }

    private void gotoTixian() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                RxBus.getDefault().postSticky(new RxKeyEvent(RxKeyEvent.MONEY_CHANGE, true));
                onBackPressed();
            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });

        TixianMethods.getInstance().encashment(subscriber,uid,hashid,getEditTextStr(etMoney),getEditTextStr(etName),getEditTextStr(etAccount));
        rxManager.add(subscriber);
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("提现");
    }
}
